home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / share / python_engine / k3d_interface.py
Encoding:
Python Source  |  2004-07-23  |  9.3 KB  |  277 lines

  1.  
  2. import _ApplicationModule
  3. import _PluginFactoryModule
  4. import _CommandNodeModule
  5. import _PropertyModule
  6. import _DocumentModule
  7. import _BezierChannelModule
  8. import _ObjectModule
  9. import _UIModule
  10. import _ScriptEnginesModule
  11. import _mesh_module
  12. import _point_module
  13. import _polyhedron_module
  14. import _face_module
  15. import _blobby_module
  16.  
  17. class ObjectClass:
  18.     def __init__(self, object):
  19.         self.__dict__["object"] = object
  20.     def __getattr__(self, method):
  21.         if method == "name":
  22.             return _ObjectModule.get_name(self.object)
  23.         elif method == "mesh":
  24.             mesh = _ObjectModule.get_mesh(self.object)
  25.             if not mesh:
  26.                 return None
  27.             return k3dmesh(self.Document(), mesh)
  28.     def __setattr__(self, method, value):
  29.         if method == "name":
  30.             return _ObjectModule.set_name(self.object, value)
  31.     def Document(self):
  32.         return DocumentClass(_ObjectModule.get_document(self.object))
  33.     def Factory(self):
  34.         return PluginFactoryClass(_ObjectModule.get_factory(self.object))
  35.     def EditObject(self):
  36.         return _ObjectModule.EditObject(self.object)
  37.  
  38. class BezierChannelClass:
  39.     def __init__(self, bezierchannel):
  40.         self.object = bezierchannel
  41.     def GetCurve(self):
  42.         return _BezierChannelModule.GetCurve(self.object)
  43.  
  44. class DocumentClass:
  45.     def __init__(self, document):
  46.         self.object = document
  47.     def GetApplication(self):
  48.         return ApplicationClass()
  49.     def GetPath(self):
  50.         return _DocumentModule.GetPath(self.object)
  51.     def Import(self, file, format):
  52.         return _DocumentModule.Import(self.object, file, format)
  53.     def Export(self, file, format):
  54.         return _DocumentModule.Export(self.object, file, format)
  55.     def Save(self, file):
  56.         return _DocumentModule.Save(self.object, file)
  57.     def StartChangeSet(self):
  58.         return _DocumentModule.StartChangeSet(self.object)
  59.     def FinishChangeSet(self, string):
  60.         return _DocumentModule.FinishChangeSet(self.object, string)
  61.     def RedrawAll(self):
  62.         return _DocumentModule.RedrawAll(self.object)
  63.     def CreateObject(self, name):
  64.         return ObjectClass(_DocumentModule.CreateObject(self.object, name))
  65.     def Objects(self):
  66.         objects = _DocumentModule.Objects(self.object)
  67.         result = []
  68.         for object in objects:
  69.             result.append(ObjectClass(object))
  70.         return result
  71.     def GetObject(self, name):
  72.         return ObjectClass(_DocumentModule.GetObject(self.object, name))
  73.     def DeleteObject(self, name):
  74.         return _DocumentModule.DeleteObject(self.object, name)
  75.     def meshes(self):
  76.         objects = _DocumentModule.get_frozen_meshes(self.object)
  77.         result = []
  78.         for object in objects:
  79.             result.append(ObjectClass(object))
  80.         return result
  81.     def mesh_instances(self):
  82.         objects = _DocumentModule.get_mesh_instances(self.object)
  83.         result = []
  84.         for object in objects:
  85.             result.append(ObjectClass(object))
  86.         return result
  87.     def objects_by_name(self, name):
  88.         objects = _DocumentModule.get_objects_by_name(self.object)
  89.         result = []
  90.         for object in objects:
  91.             result.append(ObjectClass(object))
  92.         return result
  93.  
  94. class PropertyClass:
  95.     def __init__(self, property):
  96.         self.object = property
  97.     def Name(self):
  98.         return _PropertyModule.get_property_name(self.object)
  99.     def Description(self):
  100.         return _PropertyModule.get_property_description(self.object)
  101.     def ReadOnly(self):
  102.         return _PropertyModule.get_property_read_only(self.object)
  103.  
  104. class CommandNodeClass:
  105.     def __init__(self, object):
  106.         self.__dict__["object"] = object
  107.     def Command(self, command, arguments):
  108.         return _CommandNodeModule.Command(self.object, command, arguments)
  109.     def __getattr__(self, name):
  110.         child = _CommandNodeModule.get_child(self.object, name)
  111.         if child:
  112.             return CommandNodeClass(child)
  113.         return _CommandNodeModule.get_property(self.object, name)
  114.     def __setattr__(self, name, value):
  115.         return _CommandNodeModule.set_property(self.object, name, value)
  116.     def Children(self):
  117.         return _CommandNodeModule.get_children(self.object)
  118.     def Properties(self):
  119.         return _CommandNodeModule.get_properties(self.object)
  120.     def GetNode(self, name):
  121.         child = _CommandNodeModule.get_child(self.object, name)
  122.         if child:
  123.             return CommandNodeClass(child)
  124.         return None
  125.     def GetProperty(self, name):
  126.         return _CommandNodeModule.get_property(self.object, name)
  127.     def SetProperty(self, name, value):
  128.         return _CommandNodeModule.set_property(self.object, name, value)
  129.  
  130. class UIClass:
  131.     def __init__(self, object):
  132.         self.object = object
  133.     def BrowserNavigate(self, url):
  134.         return _UIModule.BrowserNavigate(self.object, url)
  135.     def Message(self, message, title):
  136.         return _UIModule.Message(self.object, message, title)
  137.     def QueryMessage(self, message, title, buttons):
  138.         return _UIModule.QueryMessage(self.object, message, title, buttons)
  139.     def ErrorMessage(self, message, title):
  140.         return _UIModule.ErrorMessage(self.object, message, title)
  141.     def GetFilePath(self, type, prompt, promptoverwrite, oldpath):
  142.         return _UIModule.GetFilePath(self.object, type, prompt, promptoverwrite, oldpath)
  143.  
  144. class ScriptEnginesClass:
  145.     def __init__(self, object):
  146.         self.object = object
  147.     def PlayFile(filename):
  148.         return _ScriptEnginesModule.PlayFile(filename)
  149.  
  150. class PluginFactoryClass:
  151.     def __init__(self, object):
  152.         self.__dict__["object"] = object
  153.     def __getattr__(self, name):
  154.         return _PluginFactoryModule.get_attribute(self.object, name)
  155.  
  156. class ApplicationClass:
  157.     def __init__(self):
  158.         pass
  159.     def __getattr__(self, name):
  160.         value = _ApplicationModule.get_attribute(name)
  161.         if value:
  162.             if name == "UI":
  163.                 return UIClass(value)
  164.             if name == "ScriptEngine":
  165.                 return ScriptEnginesClass(value)
  166.             return value
  167.         raise AttributeError
  168.     def Close(self):
  169.         return _ApplicationModule.Close()
  170.     def NewDocument(self):
  171.         return DocumentClass(_ApplicationModule.NewDocument())
  172.     def OpenDocument(self, file):
  173.         return DocumentClass(_ApplicationModule.OpenDocument(file))
  174.     def CloseDocument(self, document):
  175.         return _ApplicationModule.CloseDocument(document.object)
  176.     def CommandNode(self, object):
  177.         return CommandNodeClass(_ApplicationModule.get_command_node(object))
  178.     def PluginFactories(self):
  179.         objects = _ApplicationModule.get_plugin_factories()
  180.         result = []
  181.         for object in objects:
  182.             result.append(PluginFactoryClass(object))
  183.         return result
  184.  
  185. class k3dmesh:
  186.     def __init__(self, document, mesh=None):
  187.         self.document = document
  188.         if mesh:
  189.             self.mesh = mesh
  190.         else:
  191.             self.mesh = _mesh_module.create_mesh()
  192.     def create_mesh_object(self):
  193.         return ObjectClass(_mesh_module.create_mesh_object(self.mesh, self.document.object))
  194.     def create_mesh_instance(self, mesh_object):
  195.         return ObjectClass(_mesh_module.create_mesh_instance(mesh_object.object, self.document.object))
  196.     def create_point(self, vector=None):
  197.         return k3dpoint(_mesh_module.create_point(self.mesh, vector))
  198.     def points(self):
  199.         objects = _mesh_module.get_points(self.mesh)
  200.         result = []
  201.         for object in objects:
  202.             result.append(k3dpoint(object))
  203.         return result
  204.     def create_polyhedron(self):
  205.         return k3dpolyhedron(_mesh_module.create_polyhedron(self.mesh), self.mesh)
  206.     def polyhedra(self):
  207.         objects = _mesh_module.get_polyhedra(self.mesh)
  208.         result = []
  209.         for object in objects:
  210.             result.append(k3dpolyhedron(object, self.mesh))
  211.         return result
  212.     def add_blobby(self, blobby_opcode):
  213.         _mesh_module.add_blobby(self.mesh, blobby_opcode.object)
  214.  
  215. class k3dpoint:
  216.     def __init__(self, object):
  217.         self.__dict__["object"] = object
  218.     def __getattr__(self, method):
  219.         if method == "position":
  220.             return _point_module.get_position(self.object)
  221.         elif method == "reference":
  222.             return _point_module.get_reference(self.object)
  223.     def __setattr__(self, method, value):
  224.         if method == "position":
  225.             return _point_module.set_position(self.object, value)
  226.  
  227. class k3dpolyhedron:
  228.     def __init__(self, polyhedron, mesh):
  229.         self.polyhedron = polyhedron
  230.         self.mesh = mesh
  231.     def __getattr__(self, method):
  232.         if method == "faces":
  233.             objects = _polyhedron_module.get_faces(self.polyhedron)
  234.             result = []
  235.             for object in objects:
  236.                 result.append(k3dface(object))
  237.             return result
  238.     def create_face(self, point):
  239.         return k3dface(_polyhedron_module.create_face(self.polyhedron, self.mesh, point.object))
  240.     def add_point_to_face(self, face, point):
  241.         _polyhedron_module.add_point_to_face(self.polyhedron, self.mesh, face.object, point.object)
  242.  
  243. class k3dface:
  244.     def __init__(self, object):
  245.         self.__dict__["object"] = object
  246.     def __getattr__(self, method):
  247.         if method == "points":
  248.             objects = _face_module.get_edge_points(self.object)
  249.             result = []
  250.             for object in objects:
  251.                 result.append(k3dpoint(object))
  252.             return result
  253.  
  254. class k3dblobby:
  255.     def __init__(self, start, end=None, radius=None):
  256.         if end and radius:
  257.             self.object = _blobby_module.segment(start, end, radius)
  258.         else:
  259.             self.object = _blobby_module.ellipsoid(start)
  260.     def set_color(self, color):
  261.         _blobby_module.set_color(self.object, color)
  262.     def add(self, blobby):
  263.         self.object = _blobby_module.add(self.object, blobby.object)
  264.     def multiply(self, blobby):
  265.         self.object = _blobby_module.multiply(self.object, blobby.object)
  266.     def max(self, blobby):
  267.         self.object = _blobby_module.max(self.object, blobby.object)
  268.     def min(self, blobby):
  269.         self.object = _blobby_module.min(self.object, blobby.object)
  270.     def subtract(self, blobby):
  271.         self.object = _blobby_module.subtract(self.object, blobby.object)
  272.     def divide(self, blobby):
  273.         self.object = _blobby_module.divide(self.object, blobby.object)
  274.  
  275. Application = ApplicationClass()
  276.  
  277.